Dog Age Calculator#90
Open
AdyaTech wants to merge 1 commit into
Open
Conversation
|
👋 @AdyaTech |
iamwatchdogs
requested changes
May 20, 2026
Contributor
iamwatchdogs
left a comment
There was a problem hiding this comment.
Hi @AdyaTech, please make the following changes to proceed with your PR:
- Update the Python script with relevant changes.
- Rename your project directory based on the specified guidelines.
Please don't create a new commit to implement the requested changes. Instead, amend the existing commit and force push the changes to the PR branch.
Comment on lines
+1
to
+16
| # Request input from the user to provide a dog's age in human years and convert it to an integer | ||
| h_age = int(input("Input a dog's age in human years: ")) | ||
|
|
||
| # Check if the entered age is less than zero; if true, display an error message and exit the program | ||
| if h_age < 0: | ||
| print("Age must be a positive number.") | ||
| exit() | ||
| # If the entered age is 2 years or less, calculate the dog's age in dog's years using the formula 10.5 times the human years | ||
| elif h_age <= 2: | ||
| d_age = h_age * 10.5 | ||
| # For ages greater than 2, calculate the dog's age in dog's years using the formula 21 plus 4 times the remaining human years after 2 | ||
| else: | ||
| d_age = 21 + (h_age - 2) * 4 | ||
|
|
||
| # Display the calculated dog's age in dog's years | ||
| print("The dog's age in dog's years is", d_age) No newline at end of file |
Contributor
There was a problem hiding this comment.
- Don't add too many comments; code should be self-documenting
- Check for valid input
- If the script fails due to unexpected behaviours, then it should exit with a non-zero code.
- The ternary operator is just a preference
Suggested change
| # Request input from the user to provide a dog's age in human years and convert it to an integer | |
| h_age = int(input("Input a dog's age in human years: ")) | |
| # Check if the entered age is less than zero; if true, display an error message and exit the program | |
| if h_age < 0: | |
| print("Age must be a positive number.") | |
| exit() | |
| # If the entered age is 2 years or less, calculate the dog's age in dog's years using the formula 10.5 times the human years | |
| elif h_age <= 2: | |
| d_age = h_age * 10.5 | |
| # For ages greater than 2, calculate the dog's age in dog's years using the formula 21 plus 4 times the remaining human years after 2 | |
| else: | |
| d_age = 21 + (h_age - 2) * 4 | |
| # Display the calculated dog's age in dog's years | |
| print("The dog's age in dog's years is", d_age) | |
| try: | |
| human_years = float(input("Input a dog's age in human years: ")) | |
| except ValueError: | |
| print("Please enter a valid number") | |
| exit(1) | |
| if human_years < 0: | |
| print("Age must be a positive number.") | |
| exit(1) | |
| dog_age = human_years * 10.5 if human_years <= 2 else 21 + (human_years - 2) * 4 | |
| print("The dog's age in dog's years is", dog_age) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐶 Dog Age Calculator (Using Python)
📌 Introduction
The Dog Age Calculator is a simple Python program that converts a dog’s age from human years into dog years using a commonly used calculation method.
The program takes user input, validates the age, and applies different formulas depending on whether the dog is younger or older than two years.
🚀 Features
💻 Example